package com.kevin.Code.LinkNode;

/**
 * @author Vinlee Xiao
 * @Classname RemoveDuplicatesFromSortedList
 * @Description Leetcode 83 删除排序链表中的重复元素  简单题
 * @Date 2021/10/29 14:50
 * @Version 1.0
 */
public class RemoveDuplicatesFromSortedList {

    /**
     * @param head
     * @return
     */
    public ListNode deleteDuplicates(ListNode head) {


        ListNode slow = head;
        ListNode fast = head;


        if (head == null) {
            return null;
        }

        if (head.next == null) {
            return head;
        }


        while (fast != null) {

            //当快慢指针的值相同
            while (fast != null && slow.val == fast.val) {
                fast = fast.next;
            }
            slow.next = fast;
            slow = fast;
//            fast = fast.next;
        }


        return head;
    }
}
